package com.applozic.mobicomkit.uiwidgets.conversation.view;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;

import com.applozic.mobicomkit.api.conversation.Message;
import com.applozic.mobicomkit.uiwidgets.AlCustomizationSettings;
import com.applozic.mobicommons.commons.core.utils.DateUtils;
import com.lottery.ruok.lottrey.R;
import com.lottery.ruok.lottrey.ui.component.BaseRelativeLayout;

import java.text.SimpleDateFormat;
import java.util.Date;

import butterknife.BindView;

public class MobicomDateView extends BaseRelativeLayout {
    @BindView(R.id.chat_screen_day)
    TextView dayTextView;
    @BindView(R.id.chat_screen_date)
    TextView dateView;
    private SimpleDateFormat simpleDateFormat;
    private SimpleDateFormat simpleDateFormatDay;

    public MobicomDateView(Context context) {
        super(context);
    }

    public MobicomDateView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MobicomDateView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void init(Context context, AttributeSet attrs, int defStyleAttr) {

    }

    @Override
    protected void initView(Context context) {
        simpleDateFormat = new SimpleDateFormat("MMM dd, yyyy");
        simpleDateFormatDay = new SimpleDateFormat("EEEE");
        setContentView(R.layout.mobicom_date_layout);

    }

    @Override
    protected void load(Context context) {

    }


    public void setData(Message message, AlCustomizationSettings alCustomizationSettings) {
        Date date = new Date(message.getCreatedAtTime());
        dateView.setTextColor(Color.parseColor(alCustomizationSettings.getConversationDateTextColor().trim()));
        dayTextView.setTextColor(Color.parseColor(alCustomizationSettings.getConversationDayTextColor().trim()));

        if (DateUtils.isSameDay(message.getCreatedAtTime())) {
            dayTextView.setVisibility(View.VISIBLE);
            dayTextView.setText(R.string.today);
        } else {
            dayTextView.setVisibility(View.VISIBLE);
            dateView.setVisibility(View.VISIBLE);
            dayTextView.setText(simpleDateFormatDay.format(date));
            dateView.setText(simpleDateFormat.format(date));
        }
    }
}
